/**
 * @author LANG - bm2736892@gmail.com
 */
float4x4 worldViewProjection : WorldViewProjection;
float4x4 world : WORLD;
float4x4 viewInverse : VIEWINVERSE;

float4 color;
samplerCUBE environmentSampler;

int isColor;

struct VertexShaderInput {
  float4 position : POSITION;
};

struct PixelShaderInput {
  float4 position : POSITION;
  float3 worldPosition : TEXCOORD0;
};

PixelShaderInput vertexShaderFunction(VertexShaderInput input) {
  	PixelShaderInput output;
	output.position = mul(input.position, worldViewProjection);
	output.worldPosition = mul(input.position, world).xyz;
 	return output;
}

float4 pixelShaderFunction(PixelShaderInput input) : COLOR {
	float4 o;
	if(isColor)
		o = color;
  	else{
	  	float3 viewVector = normalize(viewInverse[3].xyz - input.worldPosition);
	  	o = texCUBE(environmentSampler, float3(-viewVector.x,
												-viewVector.y,
												-viewVector.z));
  	}
  	return o;
}

// #o3d VertexShaderEntryPoint vertexShaderFunction
// #o3d PixelShaderEntryPoint pixelShaderFunction
// #o3d MatrixLoadOrder RowMajor